<template>
	<view class="upload">
		<view class="titleBox">
			<view class="label">
				标题:
			</view><textarea maxlength='-1' v-model="title" placeholder="" auto-height=""/>
		</view>
		<view class="textBox">
			<view class="label">
				答案:
			</view><textarea maxlength='-1' v-model="text" placeholder="" />
		</view>
		<view class="btn" @click="submit">
			<button type="default">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'',
				text:''
			};
		},
		methods:{
			submit(){
				if(this.title.trim()==''){
					uni.showToast({
						title:'请填写标题',
						icon:'none'
					})
					return
				}
				if(this.text.trim()==''){
					uni.showToast({
						title:'请填写答案',
						icon:'none'
					})
					return
				}
				this.$myRequest({
					url: '/question/post',
					method: 'post',
					data:{
						title:this.title,
						text:this.text
					}
				}).then(res => {
					uni.showToast({
						title:'提交成功',
						icon:'none'
					})
					this.title=''
					this.text=''
				})
			}
		}
	}
</script>

<style lang="less">
.titleBox,.textBox{
	padding: 20rpx;
	display: flex;
	.label{
		width: 100rpx;
	}
	textarea{
		border: 1rpx solid #ccc;
		flex: 1;
		padding: 20rpx;
	}
}
.btn{
	width: 80%;
	position: fixed;
	bottom: 15%;
	left: 50%;
	transform: translate(-50%,0);
}
</style>
